package com.smile.chatview;

import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.RenderingHints;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;

import javax.imageio.ImageIO;
import javax.swing.JLabel;

public class HeadImage extends JLabel {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	private BufferedImage image = null;

	public HeadImage() {
		try {
			image = ImageIO.read(new File("resources/img/usericon.png"));
		} catch (IOException e) {
			e.printStackTrace();
		}
	}

	public HeadImage(String imgPath) {
		this.setBounds(17, 17, 45, 45);
		try {
			image = ImageIO.read(new File("resources/img/" + imgPath));
		} catch (IOException e) {
			e.printStackTrace();
		}

	}

	public void setImagePath(String imgPath) {
		try {
//			System.out.println(imgPath);
			image = ImageIO.read(new File("resources/img/" + imgPath));
		} catch (IOException e) {
			e.printStackTrace();
		}

	}

	@Override
	protected void paintComponent(Graphics g) {

		Graphics2D g2d = (Graphics2D) g;
		g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
				RenderingHints.VALUE_ANTIALIAS_ON);
		if (image != null) {
			g2d.drawImage(image, 0, 0, 45, 45, null);
		}

		super.paintComponent(g);
	}

}
